package com.springbootmybatishw.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springbootmybatishw.dao.StudentDao;
import com.springbootmybatishw.entity.Student;
import com.springbootmybatishw.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentDao studentDao;
    @Override
    public Student selectStudentByName(String name) {
        return studentDao.findStudentByName(name);
    }

    @Override
    public List<Student> selectStudentAll() {
        return studentDao.findStudentAll();
    }
    @Override
    public PageInfo<Student> selectAllByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> list = studentDao.findStudentAll();
        PageInfo<Student> pageInfo = new PageInfo<Student>(list);
        System.out.println("=====================================分页信息====================================\n"+pageInfo
                +"\n=================================END======================================================\n");
        return pageInfo;
    }

    @Override
    public int addStudent(Student student) {
        int rows = studentDao.insertStudent(student);
        return rows;
    }

    @Override
    public int deleteStudent(Integer id) {
        int rows = studentDao.deleteStudent(id);
        return rows;
    }

    @Override
    public int editStudent(Student student) {
        int rows = studentDao.updateStudent(student);
        return rows;
    }
}
